package adfc2.tasks;

import adfc2.actions.DigAction;
import adfc2.core.*;
import adfc2.items.Pickaxe;

/**
 * Created by IntelliJ IDEA.
 * User: aimozg
 * Date: 29.01.12
 * Time: 3:46
 */
public class DigTask extends Task {

    public final int txy;
    private MoveTask moving; // TODO реализовать sub-task

    public DigTask(Creature actor, int txy) {
        super(actor);
        this.txy = txy;
    }

    static final Item PICKAXE = new Pickaxe(Material.IRON);

    @Override
    public Action nextAction() {
        if ((World.world().blocks[txy] & World.MASK_FILLED) == 0) {
            completed();
            return null;
        } else if (World.near(actor.getXY(), txy)) {
            return new DigAction(actor, txy);
        } else if (actor.hasItemLike(PICKAXE, Item.ICMASK_TYPE)) {
            if (moving == null) moving = new MoveTask(actor, txy, true);
            return moving.nextAction();
        } else {
            failed();
            return null;
        }
    }

    @Override
    public String shortName() {
        return "dig";
    }
}
